import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.safety.Whitelist;
import org.jsoup.select.Elements;
public class htmlparser
{
	public static enum TYPE
	{
		Google,//0
		Baidu,//1
		Yahoo//2
	};
	private String content;
	public htmlparser(String text)
	{
		content = text;
	}
	public void getCenter(int t)
	{
		switch(t)
		{
		case 0:
			getCenter_google();
		case 1:
			getCenter_baidu();
		case 2:
			getCenter_yahoo();
		default:
			return;
		}
	}
	private void getCenter_baidu()
	{
		Document doc = null;
		String text;
		try
		{
			doc = Jsoup.parse(content);
			Elements center = doc.select(".result-op");
			//content = center_op.toString();
			
			if(center != null)
			{
				//text = new String(center.toString().getBytes("US-ASCII"),"UTF-16");
				text = Jsoup.clean(center.toString(), Whitelist.none());
				text = new String(text.getBytes("GB2312"),"GB2312");
				System.out.println(text);
				search.content.add(text);
			}
			else
			{
				//center = doc.select(".result");
			}
			/*for(Element item : center)
			{
				text = Jsoup.clean(item.toString(), Whitelist.none());
				System.out.println(text);
			}*/
		}
		catch(Exception e)
		{
			System.out.println(e.toString());
		}
		return;
	}
	private void getCenter_yahoo()
	{
		Document doc = null;
		String text;
		try
		{
			doc = Jsoup.parse(content);
			Elements center = doc.select(".desc");
			content = center.toString();
			for(Element item : center)
			{
				text = Jsoup.clean(item.toString(), Whitelist.none());
				System.out.println(text);
				search.content.add(text);
			}
		}
		catch(Exception e)
		{
			System.out.println(e.toString());
		}
		return;
	}
	private void getCenter_google()
	{
		Document doc = null;
		String text;
		try
		{
			doc = Jsoup.parse(content);
			Elements center = doc.select("#center_col");
			content = center.toString();
			Elements items = center.select("li");
			for(Element item : items)
			{
				text = Jsoup.clean(item.toString(), Whitelist.none());
				System.out.println(text);
				search.content.add(text);
			}
		}
		catch(Exception e)
		{
			System.out.println(e.toString());
		}
		return;
	}
}